package com.taplinker.client.im.rpc.response;

import java.util.Date;

import android.util.Log;

import com.taplinker.client.AppConfigFactory;
import com.taplinker.client.App;
import com.taplinker.client.im.domain.ImDataCenter;
import com.taplinker.client.im.protocol.TapLinkerMessage;
import com.taplinker.client.im.rpc.body.Cmd1012Rep;
import com.taplinker.core.rpc.Result;
import com.taplinker.core.util.json.JsonUtil;

public class Cmd1013 implements ImResponse{

	@Override
	public void yes(Result result) {
		Cmd1012Rep value = JsonUtil.jsonToObject(result.object.toString(), Cmd1012Rep.class);
		
		TapLinkerMessage message = new TapLinkerMessage();
		message.setContent(value.getContent());
		message.setConversationId(value.getConversationId());
		message.setId(value.getId());
		message.setType(value.getType());
		message.setSendTime(new Date(value.getSendTime()));
		message.setSendUser(value.getSendUser());
		message.setSendVistor(value.getSendVisitor());
		message.setSendUserId(value.getSendUserId());
		message.setRead(value.getRead());
		
		ImDataCenter.getInstance().addToPubMessage(message);
		ImDataCenter.getInstance().noticeListener(ImDataCenter.MESSAGE_RECEIVE + message.getConversationId());
		
		Log.v("log_ktian", "新消息0000："+message.getContent());
		((App) AppConfigFactory.getInstance().getApplication()).notifyMessage(
				message.getSendUser()
				+ " 发来新消息:"
				+ message.getContent());
	}

	@Override
	public String getCommand() {
		return "1013";
	}

}
